package com.heima.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.entity.PageResult;
import com.heima.entity.QueryPageBean;
import com.heima.mapper.CheckItemMapper;
import com.heima.pojo.CheckItem;
import com.heima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;


    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        String queryString = queryPageBean.getQueryString();
        //设置 当前页和每页条数
        PageHelper.startPage(currentPage,pageSize);

        //根据条件查询 所有的检查项 如果没有 查询所有
        Page<CheckItem> checkItems = checkItemMapper.selectByCondition(queryString);
        long total = checkItems.getTotal();
        //封装 分页查询的结果集
        List<CheckItem> result = checkItems.getResult();

        return new PageResult(total,result);

    }

    @Override
    public void delete(Integer id) {
        checkItemMapper.delete(id);
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemMapper.findById(id);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemMapper.findAll();
    }
}
